/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;

/**
 *
 * @author Pro
 * are for the controlling of cars in lanes
 */
public class Lights implements Serializable {

    private int x, y, length, width;
    private boolean green = false;
    private boolean amberDelay = false;
    private boolean redWait = false;
    private Color color;

    /**
     *
     * @param i is the value associated with horizontal or vertical
     * @param xIn
     * @param yIn
     */
    public Lights(int i, int xIn, int yIn) {

        if (i == 0) {
            color = Color.GREEN;
            x = xIn;
            y = yIn;
            length = 10;
            width = 30;
            green = true;
        }

        if (i == 1) {
            color = Color.RED;
            x = xIn;
            y = yIn;
            length = 30;
            width = 10;
            green = false;
        }

    }

    /**
     *
     * @param g
     */
    public void draw(Graphics g) {

        g.setColor(color);
        g.fillRect(x, y, length, width);
    }

    /**
     *
     * @return
     */
    public synchronized int getX() {
        return x;
    }

    /**
     *
     * @return
     */
    public synchronized int getY() {
        return y;
    }

    /**
     *
     * @return
     */
    public synchronized boolean getRedWait() {
        return redWait;
    }

    /**
     *
     * @param value
     */
    public synchronized void setRedWait(boolean value) {
        this.redWait = value;
    }

    /**
     *
     * @return
     */
    public synchronized boolean getAmberDelay() {
        return amberDelay;
    }

    /**
     *
     * @param value
     */
    public synchronized void setAmberDelay(boolean value) {

        this.amberDelay = value;

        if (amberDelay) {

            color = new Color(0xF88017);
        }
    }

    // Method to set objects state.
    /**
     *
     * @param value
     */
    public synchronized void setGreen(boolean value) {
        this.green = value;

        if (value) {

            color = Color.GREEN;
        }
        if (!value) {

            color = Color.RED;
        }
    }

    /**
     *
     * @return
     */
    public synchronized boolean getGreen() {

        return this.green;
    }
}
